package com.ecarx.library_base.base_util;

import android.os.SystemClock;
import android.util.Log;
import android.view.View;

public class DebounceClickListener implements View.OnClickListener {

    private static final int MIN_CLICK_DELAY_TIME = 500;

    private long lastClickTime = 0;

    View.OnClickListener mOnClickListener;
    /**
     * @param onClickListener 快速点击保护事件
     */
    public DebounceClickListener(View.OnClickListener onClickListener) {
        this.mOnClickListener = onClickListener;
    }

    @Override
    public void onClick(View v) {
        long currentTime = SystemClock.elapsedRealtime();
        if (Math.abs(currentTime - lastClickTime) > MIN_CLICK_DELAY_TIME) {
            lastClickTime = currentTime;
            if (mOnClickListener != null) {
                mOnClickListener.onClick(v);
            }
        }
    }

}